# Build context: mono-repo root (not bare-metal-fulfillment-operator/ alone).
# Invoke with: podman build -f bare-metal-fulfillment-operator/Containerfile .
FROM registry.access.redhat.com/ubi10/go-toolset:1.26.7-1791275880 AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /opt/app-root/src
# go.work.sum is intentionally not copied in -- it's not committed to the
# repo (see root .gitignore); `go mod download` below regenerates it inside
# the build using the go.sum files already copied in per module.
COPY --chown=1001:1001 go.work ./
# proto/ is referenced by go.work; go commands in the workspace need its go.mod
# present even though this component does not import the generated types.
COPY --chown=1001:1001 proto/go.mod proto/go.sum proto/
COPY --chown=1001:1001 bare-metal-fulfillment-operator/go.mod bare-metal-fulfillment-operator/go.sum bare-metal-fulfillment-operator/
COPY --chown=1001:1001 osac-operator/go.mod osac-operator/go.sum osac-operator/
COPY --chown=1001:1001 osac-operator/api/go.mod osac-operator/api/go.sum osac-operator/api/
COPY --chown=1001:1001 fulfillment-service/go.mod fulfillment-service/go.sum fulfillment-service/
COPY --chown=1001:1001 osac-csi-driver/go.mod osac-csi-driver/go.sum osac-csi-driver/
COPY --chown=1001:1001 osac-metering/schema/go.mod osac-metering/schema/go.sum osac-metering/schema/
COPY --chown=1001:1001 osac-metering/metering-service/go.mod osac-metering/metering-service/go.sum osac-metering/metering-service/
COPY --chown=1001:1001 osac-metering/adapters/go.mod osac-metering/adapters/go.sum osac-metering/adapters/
COPY --chown=1001:1001 osac-ui/proxy/go.mod osac-ui/proxy/go.sum osac-ui/proxy/
ARG GODEBUG
RUN cd bare-metal-fulfillment-operator && go mod download

COPY --chown=1001:1001 proto/ proto/
COPY --chown=1001:1001 bare-metal-fulfillment-operator/ bare-metal-fulfillment-operator/
COPY --chown=1001:1001 osac-operator/ osac-operator/

WORKDIR /opt/app-root/src/bare-metal-fulfillment-operator
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go

FROM registry.access.redhat.com/ubi10-minimal:10.2-1790075626
LABEL name="cloud-extensions/bare-metal-fulfillment-operator-rhel10"
LABEL cpe="cpe:/a:redhat:cloud_extensions:0.1::el10"
WORKDIR /
COPY --from=builder /opt/app-root/src/bare-metal-fulfillment-operator/manager /usr/local/bin/
USER 1001

ENTRYPOINT ["/usr/local/bin/manager"]
